require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#myDelivery",
    data:{
        // name:"",
        // type:"",
        loadFlag:false,
        value:1,
        applyInfo:{},
        list:{
            loginUid:userInfo.id,
            // loginUid:1,
            pageNumber:1,
            state:""
        },
        // isScreen:"",
        recruitList:{},//列表
        recruitList1:[],
        recruitList2:[]
    },
    mounted:function(){
       this.myDeliveryList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //tab切换
        getTab:function(num){
            this.recruitList={};
            this.recruitList1=[];
            this.recruitList2=[];
            console.log(num)
            this.list.state=num;
            console.log(this.list.state)
            this.list.pageNumber=1;
            this.myDeliveryList();
        },
        getShow:function(idx){
            $("#list"+idx).find(".list-butt").toggle();
        },
        //我的投递列表
        myDeliveryList:function(){
            var that=this;
            // console.log(this)
            this.ajax({url:"/happyi/myDeliveryList",data:that.list,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.recruitList=b.json.data;
                    that.recruitList1=that.recruitList.list;
                    if(that.recruitList.pageNumber>1){
                        if(that.recruitList.list.length>0) {
                            that.recruitList2 = that.recruitList2.concat(b.json.data.list);
                        }
                    }else{
                        that.recruitList2= that.recruitList1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.recruitList={};
                    that.recruitList1=[];
                    that.recruitList2=[];
                    vm.$refs.prompt.toast("获取投递列表失败！")
                }
            });
        }
    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag = vm.recruitList.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.list.pageNumber++;
            vm.myDeliveryList();
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};